#!/bin/bash
set -e
# for single cell

function info() {
echo Usage: `basename $0` [-e err_rate -m min_len] reads1.fq[.gz], reads2.fq[.gz]
exit 65
}


while getopts  ":e:m:p:" opts
do
        case  $opts  in
		e) err_rate=$OPTARG;;
        m) min_len=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then info; fi
if [ -z "$min_len" ]; then min_len=50; fi
if [ -z "$err_rate" ]; then err_rate=0.13; fi


. /mnt/ilustre/app/medical/tools/.var

export PATH=~/../fei.yang/yn/tools/conda/bin:$PATH
. activate t27

# cutadapt=${tools_path}/cutadapt-1.8.1/bin/cutadapt

truseq_uni=AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT

truseq_uni_res_com=AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATT
truseq_uni_res_com_22=AGATCGGAAGAGCGTCGTGTAG
truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT


truseq_1=ATCTCGTATGCCGTCTTCTGCTTG

truseq1=${truseq_0}${barcode}${truseq_1}

truseq_0=GATCGGAAGAGCACACGTCTGAACTCCAGTCAC
truseq_0_22=GATCGGAAGAGCACACGTCTGA
# truseq_0_20=GATCGGAAGAGCACACGTCT
truseq_0_20=AGATCGGAAGAGCACACGTC
#           AGATCGGAAGAGC
 # GATCGGAAGAGCACACGTCT
# AGATCGGAAGAGCGTCGTGT
# $cutadapt \
# -n 2 \
# -q 10 \
# --trimmed-only \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

# $cutadapt \
# -n 2 \
# -q 10 \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2


# ${tools_path}/Python-2.7.10/python \
# $

cutadapt \
--overlap 6 \
-e $err_rate \
-n 2 \
-m $min_len \
-a $truseq_0_20 \
-A $truseq_uni_res_com_20 \
-o $out_prefix.1.cut.fastq \
-p $out_prefix.2.cut.fastq \
$1 $2

. $cmd_done

# $cutadapt \
# -u +20 \
# -u -20 \
# -U +20 \
# -U -20 \
# -m 20 \
# -o $s1.trimmed.fastq \
# -p $s2.trimmed.fastq \
# $s1.cut.fastq \
# $s2.cut.fastq \
# 2>>$log 1>&2

# len5=21
# len3=25

# $cutadapt \
# -u +$len5 \
# -u -$len3 \
# -U +$len5 \
# -U -$len3 \
# -o $out_prefix.1.trimmed.fastq \
# -p $out_prefix.2.trimmed.fastq \
# $out_prefix.1.cut.fastq \
# $out_prefix.2.cut.fastq \
# 2>>$log 1>&2

